@extends('admin::index')

@section('content')
    <section class="content-header">
        <h1>
            {{ $edit_header or trans('admin.title') }}
            <small>{{ $edit_description or trans('admin.description') }}</small>
        </h1>

    </section>

    <section class="content">
        {{-- tian add flash --}}
        @include('flash::message')
        @include('admin::partials.error')
        @include('admin::partials.success')
        @include('admin::partials.exception')
        @include('admin::partials.toastr')
      @php
      @endphp
        <div class="box box-info">
            <div class="box-header with-border">
                <h3 class="box-title">创建</h3>

                <div class="box-tools">
                    <div class="btn-group pull-right" style="margin-right: 10px">
                        <a href="{{ route('application.pagetpl_areas.index') }}" class="btn btn-sm btn-default"><i class="fa fa-list"></i>&nbsp;列表</a>
                    </div> <div class="btn-group pull-right" style="margin-right: 10px">
                        <a class="btn btn-sm btn-default form-history-back" href="javascript:window.history.go(-1);"><i class="fa fa-arrow-left"></i>&nbsp;返回</a>
                    </div>
                </div>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form action="" method="post" accept-charset="UTF-8" class="form-horizontal" pjax-container="">
                <div class="box-body">
                    <div class="fields-group">
                    <!-- 考核周期 -->
                    <div class="form-group">
                        <label for="pagetpl_id" class="col-sm-2 control-label">pageTpl模板名称</label>
                        <div class="col-sm-8">
                            <select class="form-control" style="width: 100%;" name="pagetpl_id" id="pagetpl_id">
                                <option value="0">请选择pageTpl模板</option>
                                @foreach($pagetpls as $key => $value)
                                    <option value="{{ $key }}" {{ ($key == $pagetplArea['pagetpl_id']) ? 'selected' : '' }} >{{ $value }}</option>
                                @endforeach
                            </select>
                        </div>
                    </div>
                    <!-- 区位编号 -->
                    <div class="form-group">
                        <label for="area" class="col-sm-2 control-label">area</label>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="text" id="area" name="area" value="{{ $pagetplArea['area'] }}"  class="form-control area" placeholder="输入area">
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="paneltpl_type_id" class="col-sm-2 control-label">模板类型</label>
                        <div class="col-sm-8">
                            <select class="form-control" style="width: 100%;" name="paneltpl_type_id" id="paneltpl_type_id">
                                <option value="0">请选择模板类型</option>
                                @foreach($paneltplTypes as $key => $value)
                                    <option value="{{ $key }}" {{ ($key == $pagetplArea['paneltpl_type_id']) ? 'selected' : '' }} >{{ $value }}</option>
                                @endforeach
                            </select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="tpl_id" class="col-sm-2 control-label">模型名称</label>
                        <div class="col-sm-8">
                            <select class="form-control" style="width: 100%;" name="tpl_id" id="tpl_id">
                            </select>
                        </div>
                    </div>
                    <!-- inner -->
                    <div class="form-group">
                        <label for="inner" class="col-sm-2 control-label">inner</label>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="text" id="inner" name="inner" value="{{ $pagetplArea['inner'] }}"  class="form-control inner" placeholder="输入inner">
                            </div>
                        </div>
                    </div>
                   <!-- onup -->
                    <div class="form-group">
                        <label for="onup" class="col-sm-2 control-label">onup</label>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="text" id="onup" name="onup" value="{{ $pagetplArea['onup'] }}"  class="form-control onup" placeholder="输入inner">
                            </div>
                        </div>
                    </div>
                    <!-- ondown -->
                    <div class="form-group">
                        <label for="ondown" class="col-sm-2 control-label">ondown</label>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="text" id="ondown" name="ondown" value="{{ $pagetplArea['ondown'] }}"  class="form-control ondown" placeholder="输入ondown">
                            </div>
                        </div>
                    </div>
                    <!-- onleft -->
                    <div class="form-group">
                        <label for="onleft" class="col-sm-2 control-label">onleft</label>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="text" id="onleft" name="onleft" value="{{ $pagetplArea['onleft'] }}"  class="form-control onleft" placeholder="输入onleft">
                            </div>
                        </div>
                    </div>
                     <!-- onright -->
                    <div class="form-group">
                        <label for="onright" class="col-sm-2 control-label">onright</label>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="text" id="onright" name="onright" value="{{ $pagetplArea['onright'] }}"  class="form-control onright" placeholder="输入onright">
                            </div>
                        </div>
                    </div>
                   <!-- onright -->
                    <div class="form-group">
                        <label for="options" class="col-sm-2 control-label">options</label>
                        <div class="col-sm-8">
                            <div class="input-group">
                                <span class="input-group-addon"><i class="fa fa-pencil"></i></span>
                                <input type="text" id="options" name="options" value="{{ $pagetplArea['options'] }}"  class="form-control options" placeholder="输入options">
                            </div>
                        </div>
                    </div>
                         <!-- onright -->
                    <div class="form-group">
                        <label for="description" class="col-sm-2 control-label">说明</label>
                        <div class="col-sm-8">
                            <textarea name="description"  id="description" class="form-control" rows="5" placeholder="输入 说明">{{ $pagetplArea['description'] }}</textarea>
                        </div>
                    </div>
                </div>
                 </div>
                <div class="box-footer">
                    <div class="2">

                    </div>
                    <div class="8">

                        <div class="btn-group pull-right">
                            <button type="submit" class="btn btn-info pull-right" id="btn_edit_pagetpl_areas" data-loading-text="<i class='fa fa-spinner fa-spin '></i> Submit">提交</button>
                        </div>

                        <div class="btn-group pull-left">
                            <button type="reset" class="btn btn-warning">重置</button>
                        </div>
                    </div>

                </div>

            </form>
        </div>
    </section>
    <script type="text/javascript">
        $(function () {
            var selectTpldataId =  '{{ $pagetplArea['tpl_id'] }}';
            // 第一次进入页面
            var paneltplTypeId =  $("#paneltpl_type_id").val();
            console.log(selectTpldataId);
            console.log(paneltplTypeId);
            // 回填模型名称数据
            $.ajax({
                url : '/admin/application/pagetpl_areas/paneltpl_types/'+paneltplTypeId+'/tpldatas',
                type:'get',
                cache: false,
                dataType:'json',
                async:true,
                success:function(data){
                    console.log(data);
                    if (data.status) {
                        $("#tpl_id").empty();// jq写法 清楚地区下拉框的所有内容，然后拼接上从后台取出来的数据
                        $("<option value=''>请选择</option>").appendTo("#tpl_id");
                        var tplData = data.content;
                        for(var i=0;i<tplData.length;i++){//获取tplData里面的数据，拼接到select上
                            if (tplData[i].id == selectTpldataId) {
                                $("#tpl_id").append("<option value='"+tplData[i].id+"' selected >"+tplData[i].title+"</option>");

                            }else{
                                $("#tpl_id").append("<option value='"+tplData[i].id+"'>"+tplData[i].title+"</option>");
                            }
                        }
                    } else {
                        // layer.msg(data.content, {
                        //     icon: 5
                        // });
                    }

                },
                error: function() {
                    layer.msg("异常！");
                }
            });

            $("#paneltpl_type_id").change(function(){
                var selectPaneltplTypeId =  $("#paneltpl_type_id").val();
                var paneltpl_type_id={"paneltpl_type_id":selectPaneltplTypeId};
                $.ajax({
                    url : '/admin/application/pagetpl_areas/paneltpl_types/'+selectPaneltplTypeId+'/tpldatas',
                    type:'get',
                    cache: false,
                    data:paneltpl_type_id,
                    dataType:'json',
                    async:true,
                    success:function(data){
                        if (data.status) {
                            $("#tpl_id").empty();// jq写法 清楚地区下拉框的所有内容，然后拼接上从后台取出来的数据
                            $("<option value=''>请选择</option>").appendTo("#tpl_id");
                            var tplData = data.content;
                            for(var i=0;i<tplData.length;i++){//获取tplData里面的数据，拼接到select上
                                $("#tpl_id").append("<option value='"+tplData[i].id+"'>"+tplData[i].title+"</option>");
                            }
                        } else {
                            layer.msg(data.content, {
                                icon: 5
                            });
                        }
                    },
                    error: function() {
                        layer.msg("异常！");
                    }
                });
            });
        });
    </script>
@endsection
